package org.shoppingcart.business;

import org.hibernate.Session;
import org.shoppingcart.datamodel.DataEntity;
import org.shoppingcart.util.HibernateUtil;

public abstract class SimpleCRUDBean {

	public abstract Class<DataEntity> getDataClass();
	
	public DataEntity getById(int id) {
		Session session = HibernateUtil.getSession();
		return (DataEntity) session.get(getDataClass(), new Integer(id));
	}
	
	public void insert(DataEntity entity) {
		HibernateUtil.getSession().save(entity);
	}
	
	public void update(DataEntity entity) {
		HibernateUtil.getSession().saveOrUpdate(entity);
	}
	
	public void delete(DataEntity entity) {
		HibernateUtil.getSession().delete(entity);
	}
}
